﻿using System;
using System.Collections.Generic;
using System.Text;
using Zove.Runtime;
using System.Windows.Media.Media3D;

namespace WPF3DTutorial.Model {
    public class CubeVisualizer : AbstractModelVisualizer {

        public CubeVisualizer(Window1 window)
            : base(window) {
            SolutionFactory factory = new SolutionFactory();
            this.solution = factory.CreateSolution("Cube");
        }

        public override Model3DGroup Draw() {
            RuntimeFactor rf = this.solution.Model.GetFactorByName("edge");
            double length = rf.Value;

            Model3DGroup cube = new Model3DGroup();
            Point3D p0 = new Point3D(0, 0, 0);
            Point3D p1 = new Point3D(length, 0, 0);
            Point3D p2 = new Point3D(length, 0, length);
            Point3D p3 = new Point3D(0, 0, length);
            Point3D p4 = new Point3D(0, length, 0);
            Point3D p5 = new Point3D(length, length, 0);
            Point3D p6 = new Point3D(length, length, length);
            Point3D p7 = new Point3D(0, length, length);

            //front side triangles
            cube.Children.Add(window.CreateTriangleModel(p3, p2, p6));
            cube.Children.Add(window.CreateTriangleModel(p3, p6, p7));
            //right side triangles
            cube.Children.Add(window.CreateTriangleModel(p2, p1, p5));
            cube.Children.Add(window.CreateTriangleModel(p2, p5, p6));
            //back side triangles
            cube.Children.Add(window.CreateTriangleModel(p1, p0, p4));
            cube.Children.Add(window.CreateTriangleModel(p1, p4, p5));
            //left side triangles
            cube.Children.Add(window.CreateTriangleModel(p0, p3, p7));
            cube.Children.Add(window.CreateTriangleModel(p0, p7, p4));
            //top side triangles
            cube.Children.Add(window.CreateTriangleModel(p7, p6, p5));
            cube.Children.Add(window.CreateTriangleModel(p7, p5, p4));
            //bottom side triangles
            cube.Children.Add(window.CreateTriangleModel(p2, p3, p0));
            cube.Children.Add(window.CreateTriangleModel(p2, p0, p1));

            return cube;
        }
    }
}
